//
//  PublicerviceViewController.m
//  ZHIFUBAO
//
//  Created by 高新川 on 15/6/16.
//  Copyright (c) 2015年 高新川. All rights reserved.
//

#import "PublicerviceViewController.h"
#import "ServiceModal.h"
#import "ServiceTableViewCell.h"
#import "SelectViewController.h"

@interface PublicerviceViewController ()

@end

@implementation PublicerviceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.modal = [[ServiceModal alloc] init];
    self.title = @"服务窗";
    
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    searchBar.placeholder = @"搜索服务窗";
    
    // 添加 searchbar 到 headerview
    self.tableView.tableHeaderView = searchBar;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.modal.datas count];
}

// 几个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

// 设置样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellWithIdentifier = @"tableCell";
    ServiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
    if (cell == nil) {
        cell = [[ServiceTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellWithIdentifier];
    }
    
    cell.image.image = [UIImage imageNamed:((ServiceUnitl *)[self.modal.datas objectAtIndex:indexPath.row]).image];
    cell.title.text = ((ServiceUnitl *)[self.modal.datas objectAtIndex:indexPath.row]).title;
    cell.detail.text = ((ServiceUnitl *)[self.modal.datas objectAtIndex:indexPath.row]).detail;
    
    return cell;
}

// 设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60.0;
}

// 点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SelectViewController *con = [[SelectViewController alloc] initWithUnitl:[self.modal.datas objectAtIndex:indexPath.row]];
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:con];
    
    [self presentViewController:navigation animated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
